/*     */ package com.zimbra.cs.dav.caldav;
/*     */ 
/*     */ import com.zimbra.common.account.Key.AccountBy;
/*     */ import com.zimbra.common.calendar.ZCalendar.ICalTok;
/*     */ import com.zimbra.common.calendar.ZCalendar.ZComponent;
/*     */ import com.zimbra.common.calendar.ZCalendar.ZProperty;
/*     */ import com.zimbra.common.calendar.ZCalendar.ZVCalendar;
/*     */ import com.zimbra.common.localconfig.DebugConfig;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.util.AccountUtil.AccountAddressMatcher;
/*     */ import java.util.Iterator;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class CalDavUtils
/*     */ {
/*     */   public static void removeAttendeeForOrganizer(ZCalendar.ZComponent comp)
/*     */   {
/*     */     String organizer;
/*     */     AccountUtil.AccountAddressMatcher acctMatcher;
/*     */     Iterator<ZCalendar.ZProperty> propIter;
/*  38 */     if ((!DebugConfig.caldavAllowAttendeeForOrganizer) && ((ZCalendar.ICalTok.VEVENT.equals(comp.getTok())) || (ZCalendar.ICalTok.VTODO.equals(comp.getTok()))))
/*     */     {
/*  40 */       organizer = comp.getPropVal(ZCalendar.ICalTok.ORGANIZER, null);
/*  41 */       if (organizer != null) {
/*  42 */         organizer = organizer.trim();
/*  43 */         acctMatcher = null;
/*  44 */         String address = stripMailto(organizer);
/*  45 */         if (address != null) {
/*     */           try {
/*  47 */             Account acct = Provisioning.getInstance().get(Key.AccountBy.name, address);
/*  48 */             if (acct != null) {
/*  49 */               acctMatcher = new AccountUtil.AccountAddressMatcher(acct);
/*     */             }
/*     */           }
/*     */           catch (ServiceException e) {
/*  53 */             ZimbraLog.dav.warn("could not get the account matcher for " + address, e);
/*     */           }
/*     */         }
/*  56 */         for (propIter = comp.getPropertyIterator(); propIter.hasNext();) {
/*  57 */           ZCalendar.ZProperty prop = (ZCalendar.ZProperty)propIter.next();
/*  58 */           if (ZCalendar.ICalTok.ATTENDEE.equals(prop.getToken())) {
/*  59 */             String att = prop.getValue();
/*  60 */             if (att != null) {
/*  61 */               att = att.trim();
/*     */               try
/*     */               {
/*  64 */                 if ((att.equalsIgnoreCase(organizer)) || ((acctMatcher != null) && (acctMatcher.matches(stripMailto(att))))) {
/*  65 */                   propIter.remove();
/*     */                 }
/*     */               }
/*     */               catch (ServiceException e) {
/*  69 */                 ZimbraLog.dav.warn("exception while matching the attendee address " + att, e);
/*     */               }
/*     */             }
/*     */             else {
/*  73 */               propIter.remove();
/*     */             }
/*     */           }
/*     */         }
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   public static void removeAttendeeForOrganizer(ZCalendar.ZVCalendar cal) {
/*  82 */     for (Iterator<ZCalendar.ZComponent> compIter = cal.getComponentIterator(); compIter.hasNext();) {
/*  83 */       removeAttendeeForOrganizer((ZCalendar.ZComponent)compIter.next());
/*     */     }
/*     */   }
/*     */   
/*     */   public static void adjustPercentCompleteForToDos(ZCalendar.ZVCalendar cal) {
/*  88 */     for (Iterator<ZCalendar.ZComponent> compIter = cal.getComponentIterator(); compIter.hasNext();) {
/*  89 */       ZCalendar.ZComponent comp = (ZCalendar.ZComponent)compIter.next();
/*  90 */       if (ZCalendar.ICalTok.VTODO.equals(comp.getTok()))
/*  91 */         adjustPercentCompleteForTodo(comp);
/*     */     }
/*     */   }
/*     */   
/*     */   private static void adjustPercentCompleteForTodo(ZCalendar.ZComponent comp) {
/*  96 */     boolean isCompleted = false;
/*  97 */     if (comp.getProperty(ZCalendar.ICalTok.COMPLETED) != null) {
/*  98 */       isCompleted = true;
/*     */     } else {
/* 100 */       ZCalendar.ZProperty status = comp.getProperty(ZCalendar.ICalTok.STATUS);
/* 101 */       if ((status != null) && (status.getValue().equals(ZCalendar.ICalTok.COMPLETED.toString())))
/* 102 */         isCompleted = true;
/*     */     }
/* 104 */     if (!isCompleted)
/*     */     {
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 110 */       ZCalendar.ZProperty percentComplete = comp.getProperty(ZCalendar.ICalTok.PERCENT_COMPLETE);
/* 111 */       if ((percentComplete != null) && (percentComplete.getIntValue() == 100))
/* 112 */         percentComplete.setValue(Integer.toString(0));
/*     */     }
/*     */   }
/*     */   
/*     */   public static String stripMailto(String address) {
/* 117 */     if ((address != null) && (address.toLowerCase().startsWith("mailto:"))) {
/* 118 */       return address.substring(7);
/*     */     }
/* 120 */     return address;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/dav/caldav/CalDavUtils.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */